﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;

namespace EnvironSystem
{
    public class CircleAreaComputer : AreaComputerBase
    {
        private EnvironmentManager manager;
        public CircleAreaComputer(IEnvironmentManager manager) : base(manager)
        {
            this.manager =(EnvironmentManager)manager;
        }

        public override IEnvironmentElement[] GetElementsInArea(IAreaArgs args)
        {
            CircleAreaArgs circleArgs = (CircleAreaArgs)args;
            List<IEnvironmentElement> elements = new List<IEnvironmentElement>();
            if (circleArgs!=null)
            {
                foreach (var item in manager.id2Elements)
                {
                    for (int i = 0; i < item.Value.Count; i++)
                    {
                        if(Vector3.Distance(circleArgs.Center, item.Value[i].Trans.position) <= circleArgs.Radius)
                        {
                            elements.Add(item.Value[i]);
                        }
                    }
                }
            }
            return elements.ToArray();

        }
    }
}
